"use client"; import { GameListRep, searchGameListApi, SearchProps } from "@/api/home"; import GroupCard from "@/components/Card/GroupCard"; import { useRouter } from "@/i18n/routing"; import { useSearchStore } from "@/stores/useSearchStore"; import { Button, createErrorBlock, SearchBar } from "antd-mobile"; import { useTranslations } from "next-intl"; import { ChangeEvent, FC, MouseEvent, PropsWithChildren, useRef, useState } from "react"; interface Props {} interface ContentProps { closeHandler: () => void; } const ErrorBlock = createErrorBlock({ empty:
, default:
, }); const Content: FC = (props) => { const t = useTranslations("HomePage"); const { closeHandler } = props; const [games, setGames] = useState([]); const searchBarRef = useRef(null); const [searchValue, setSearchValue] = useState(""); const { history, setHistory, removeKey, removeAllKey } = useSearchStore(); const [visible, setVisible] = useState(false); const params = useRef({ current_page: 1, page_size: 15, use_page: true, search_game_name: "", }); const getGames = async (): Promise => { return searchGameListApi(params.current).then((res) => { setVisible(!res.page.is_end); if (res.data) { return res.data; } }); }; const isPending = () => games.length === 0 && params.current.search_game_name === "" && params.current.current_page === 1; const setSearchValueInit = (value: string, isPush = true) => { params.current.search_game_name = value; getGames().then((data) => { if (data && data.length > 0 && value.trim() !== "" && isPush) { setHistory(value); } data && setGames(data); }); }; // const func = debounce(setSearchValueInit, 500); // const changeHandler = (value: string) => { // if (value) func(value); // }; const blurHandler = (event: ChangeEvent) => { const value = event.target.value; if (value.trim() === "") return; setSearchValueInit(value); }; const onCancel = () => { closeHandler(); params.current.current_page = 1; params.current.search_game_name = ""; setGames([]); setVisible(false); }; // 历史记录单项点击事件 const historyItemHandler = (key: string) => { if (key === params.current.search_game_name) return; setSearchValue(key); setSearchValueInit(key, false); }; const removeHistoryItem = (event: MouseEvent, item: string) => { event.stopPropagation(); removeKey(item); }; const nextHandler = async () => { params.current.current_page++; return getGames().then((data) => data && setGames((games) => games.concat(data))); }; return (
{games.length ? ( ) : ( )}
{visible && ( )}
); }; const HomeSearch: FC> = (props) => { const router = useRouter(); const t = useTranslations("HomePage"); const [visible, setVisible] = useState(false); const handler = () => { router.push("/search"); }; return ( <>
Nome do Jogo
{/* setVisible(false)} /> */} ); }; export default HomeSearch;